using Microsoft.Xna.Framework;
using System.Globalization;
using System.Collections.Generic;

namespace XeoEngine
{
    class OptionsMenuScreen : MenuScreen
    {
        MenuEntry languageMenuEntry;
        MenuEntry back;
        MenuEntry graphicsMenuEntry;
        MenuEntry soundMenuEntry;
        List<string> Languages = new List<string>() 
        {
            "en",
            "ru"
        };
        int lngnum;

        public OptionsMenuScreen()
            : base(Localizations.Strings.Options)
        {
            lngnum = Languages.IndexOf(Localizations.Strings.Culture.IetfLanguageTag);
            languageMenuEntry = new MenuEntry(Localizations.Strings.Language + " - " + Localizations.Strings.LanguageName);
            graphicsMenuEntry = new MenuEntry(Localizations.Strings.Graphics);
            soundMenuEntry = new MenuEntry(Localizations.Strings.Sound);
            back = new MenuEntry(Localizations.Strings.Back);
            graphicsMenuEntry.Selected += GraphicsMenuEntrySelected;
            languageMenuEntry.Selected += LanguageMenuEntrySelected;
            soundMenuEntry.Selected += SoundMenuEntrySelected;
            back.Selected += BackMenuEntrySelected;
            MenuEntries.Add(languageMenuEntry);
            MenuEntries.Add(graphicsMenuEntry);
            MenuEntries.Add(soundMenuEntry);
            MenuEntries.Add(back);
        }

        void LanguageMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            lngnum++;
            if (lngnum >= Languages.Count) lngnum = 0;
            Localizations.Strings.Culture = CultureInfo.GetCultureInfo(Languages[lngnum]);
            languageMenuEntry.Text = Localizations.Strings.Language + " - " + Localizations.Strings.LanguageName;
            graphicsMenuEntry.Text = Localizations.Strings.Graphics;
            soundMenuEntry.Text = Localizations.Strings.Sound;
            back.Text = Localizations.Strings.Back;
            MenuTitle = Localizations.Strings.Options;            
        }

        void GraphicsMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.AddScreen(new GraphicOptionsMenuScreen(ScreenManager.Graphics.PreferredBackBufferWidth, ScreenManager.Graphics.PreferredBackBufferHeight, ScreenManager.Graphics.SynchronizeWithVerticalRetrace, ScreenManager.Graphics.PreferMultiSampling, ScreenManager.Graphics.IsFullScreen), e.PlayerIndex);
        }

        void SoundMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.AddScreen(new SoundOptionsMenuScreen(), e.PlayerIndex);
        }

        void BackMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            GraphicOptionsMenuScreen.SaveSettings(ScreenManager);
            OnCancel(e.PlayerIndex);
        }
    }
}
